<?php
FLEA::loadClass('FLEA_Helper_Pager');
class Controller_Pager extends FLEA_Helper_Pager { 

	function getNavBar($mpurl,$kwords=null) {
		$multipage = '';
		$num = $this->count;//符合条件的记录总数
		$mpurl .= strpos($mpurl, '?') ? '&amp;' : '?';
		$curpage = $this->currentPage;
		$perpage = $this->pageSize;
		$maxpages = 0;           
        $url = FLEA::getAppInf('webAddr');
		if (!isset($kwords)){
			$mpurl = $url.'/page/';
		}else{
			$mpurl = $url.'/search?kwords='.$kwords.'&page=';
		}
		if($num > $this->pageSize) {
			$page = 5; //每屏允许显示的页数
			$offset = 2;//偏移量
			$pages = $this->pageCount;
			if($page > $pages) {	//总页数不足每屏显示个数
				$from = 1;
				$to = $pages;
			} else {//总页数多于每屏显示个数
				$from = $curpage - $offset + 1;
				$to = $from + $page - 1;
				if($from < 1) {
					$to = $curpage - $from + 1;
					$from = 1;
					if($to - $from < $page) {
						$to = $page;
					}
				} elseif($to > $pages) {
					$from = $pages - $page + 1;
					$to = $pages;
				}                           
			}
			$firstPage = $this->firstPage + 1;
			$prevPage = $this->prevPage + 1;
			$nextPage = $this->nextPage + 1;
			$lastPage = $this->lastPage + 1;
			$multipage = ($curpage > $offset && $pages > $page ? '<a class="PageBar_Nav" href="'.$mpurl.$firstPage.'">|&lt;</a>' : '').
					   ($curpage > 0 ? '<a class="PageBar_Nav" href="'.$mpurl.$prevPage.'">&lt;&lt;</a>' : '');
			//dump($multipage);
			for($i = $from; $i <= $to; $i++) {
				$multipage .= $i == $curpage + 1 ? '<a class="PageBar_Current">'.$i.'</a>' : '<a class="PageBar_Num" href="'.$mpurl.($i).'">'.$i.'</a>';
			}

			$multipage .= ($curpage+1 < $pages ? '<a class="PageBar_Nav" href="'.$mpurl. $nextPage .'">&gt;&gt;</a>' : '').
					   ($to < $pages ? '<a class="PageBar_Nav" href="'.$mpurl. $lastPage .'">&gt;|</a>' : '').
					   ($pages > $page ? '<input class="p_input" type="text" name="custompage" onkeypress="if(event.keyCode==13){window.location.href=\''.$mpurl.'\'+(this.value);}">' : '');

			//$multipage = $multipage ? '<div class="p_bar"><a class="p_total"> '.$num.' </a><a class="p_pages"> '.$this->currentPageNumber.'/'.$this->pageCount.' </a>'.$multipage.'</div>' : '';
			$multipage = $multipage ? '<div id="PageBar"><a class="PageBar_Pages"> '.$this->currentPageNumber.'/'.$this->pageCount.' </a>'.$multipage.'</div>' : '';
		}
	
		return $multipage;
	} 
}

class Controller_AdminPager extends FLEA_Helper_Pager { 

	function getNavBar($mpurl) {
		$multipage = '';
		$num = $this->count;//符合条件的记录总数
		$mpurl .= strpos($mpurl, '?') ? '&' : '?';
		$curpage = $this->currentPage;
		$perpage = $this->pageSize;
		$maxpages = 0;           
        $url = FLEA::getAppInf('webAddr');
		$mpurl = $url.$mpurl.'page=';
		if($num > $this->pageSize) {
			$page = 5; //每屏允许显示的页数
			$offset = 2;//偏移量
			$pages = $this->pageCount;
			if($page > $pages) {	//总页数不足每屏显示个数
				$from = 1;
				$to = $pages;
			} else {//总页数多于每屏显示个数
				$from = $curpage - $offset + 1;
				$to = $from + $page - 1;
				if($from < 1) {
					$to = $curpage - $from + 1;
					$from = 1;
					if($to - $from < $page) {
						$to = $page;
					}
				} elseif($to > $pages) {
					$from = $pages - $page + 1;
					$to = $pages;
				}                           
			}
			$firstPage = $this->firstPage + 1;
			$prevPage = $this->prevPage + 1;
			$nextPage = $this->nextPage + 1;
			$lastPage = $this->lastPage + 1;
			$multipage = ($curpage > $offset && $pages > $page ? '<a class="PageBar_Nav" href="'.$mpurl.$firstPage.'">|&lt;</a>' : '').
					   ($curpage > 0 ? '<a class="PageBar_Nav" href="'.$mpurl.$prevPage.'">&lt;&lt;</a>' : '');
			//dump($multipage);
			for($i = $from; $i <= $to; $i++) {
				$multipage .= $i == $curpage + 1 ? '<a class="PageBar_Current">'.$i.'</a>' : '<a class="PageBar_Num" href="'.$mpurl.($i).'">'.$i.'</a>';
			}

			$multipage .= ($curpage+1 < $pages ? '<a class="PageBar_Nav" href="'.$mpurl. $nextPage .'">&gt;&gt;</a>' : '').
					   ($to < $pages ? '<a class="PageBar_Nav" href="'.$mpurl. $lastPage .'">&gt;|</a>' : '').
					   ($pages > $page ? '<input class="p_input" type="text" name="custompage" onkeypress="if(event.keyCode==13){window.location.href=\''.$mpurl.'\'+(this.value);}">' : '');

			//$multipage = $multipage ? '<div class="p_bar"><a class="p_total"> '.$num.' </a><a class="p_pages"> '.$this->currentPageNumber.'/'.$this->pageCount.' </a>'.$multipage.'</div>' : '';
			$multipage = $multipage ? '<div id="PageBar"><a class="PageBar_Pages"> '.$this->currentPageNumber.'/'.$this->pageCount.' </a>'.$multipage.'</div>' : '';
		}
	
		return $multipage;
	} 
}
?>